    <?php
class NoticiasController extends Zend_Controller_Action
{
    public function init(){
        $formLogin = new Application_Form_Login();
        $this->view->formLogin = $formLogin;
        $model =new Application_Model_Noticias();
        $this-> view->noticias=$model->getAll();
        $modelTesis =new Application_Model_Tesis();
        $this-> view->tesis=$modelTesis->getAll();
        $modelPersona =new Application_Model_Personas();
        $this-> view->persona=$modelPersona->getAll();
        if(Zend_Auth::getInstance()->hasIdentity()){
            $skin=Zend_Auth::getInstance()->getIdentity()->skin;
            $this->_helper->Cambiarskin($skin);
        }
    }
    public function verAction() {

        $model =new Application_Model_Noticias();
        $this-> view->noticias=$model->getAll();

    }
    public function listarAction()
    {
        $model =new Application_Model_Noticias();
        $this-> view->noticias=$model->getAll();
 
    }
    public function agregarAction()
    {
        $formNoticia=new Application_Form_Noticia();
        
        if($this->getRequest()->isPost()){
            if($formNoticia->isValid($this->_getAllParams())){
                $model=new Application_Model_Noticias();
                $model->save($formNoticia->getValues());
                return $this->_redirect('/noticias/listar');
            }
        }
        $this->view->formNoticia=$formNoticia;
     
    }
    public function editarAction(){
        
        if(!$this->hasParam('id_noticia')){
            return $this->_redirect('/noticias/listar');
        }
        $formNoticia=new Application_Form_Noticia();
        $modelNoticia2=new Application_Model_Noticias();
        
        if($this->getRequest()->isPost()){
            if($formNoticia->isValid($this->_getAllParams())){
                $modelNoticia=new Application_Model_Noticias();
                $modelNoticia->save($formNoticia->getValues(),$this->_getParam('id_noticia'));
                return $this->_redirect('/noticias/listar');
            }
        }else{
            $row=$modelNoticia2->getRow($this->_getParam('id_noticia'));
            if($row){
                $formNoticia->populate($row->toArray());
                
            }else{
               return $this->_redirect('/noticias/listar'); 
            }
        }
        $this->view->formNoticia=$formNoticia;
    }

}
